package com.bw.journal.insert

import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.DialogFragment
import androidx.recyclerview.widget.GridLayoutManager
import com.bawei.module_journal.databinding.LayoutJournalTypeBinding

import com.bw.journal.insert.entity.JournalTypeEntity


class JounalTypeFragment : DialogFragment() {

    private val v : LayoutJournalTypeBinding by lazy {
        LayoutJournalTypeBinding.inflate(LayoutInflater.from(requireContext()))
    }

    private val timeArray : Array<String> = arrayOf("1","7","30","季度","业绩","营业")
    private val valueArray : Array<String> = arrayOf("日报","周报","月报","季度报表","业绩报表","营业财报")
    private val typeArray : ArrayList<JournalTypeEntity> =ArrayList<JournalTypeEntity>()
    private val typeAdapter : JournalTypeAdapter by lazy { JournalTypeAdapter() }
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        initData()
        v.journalTypeCanel.setOnClickListener { requireActivity().finish() }
        val manager = GridLayoutManager(requireContext(),3)
        manager.orientation = GridLayoutManager.VERTICAL
        v.journalTypeRv.layoutManager = manager
 //       v.journalTypeRv.addItemDecoration(JournalTypeDecoration(requireContext()))
        v.journalTypeRv.adapter = typeAdapter
        typeAdapter.setOnItemCLickListener{adpter,position->
            var typeActivity : JournalInsertActivity = requireActivity() as JournalInsertActivity
            typeActivity.type = position+1
            typeActivity.refreshView()
            parentFragmentManager.beginTransaction().remove(this).commit()
        }
        typeAdapter.setNewInstance(typeArray)
        return v.root
    }

    private fun initData(){
        Log.e("ZXY","initData:"+timeArray.size)
        var index = 0
        while (index<timeArray.size){
            typeArray.add(JournalTypeEntity(timeArray[index],valueArray[index]))
            index++
        }
    }

}